home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 386 / utility / cmd_test.s < prev    next >
Text File  |  1985-11-19  |  10KB  |  229 lines

  1.  ; Program Name: CMD_TEST.S
  2.  ; Version 1.004
  3.  
  4.  ; Assembly Instructions:
  5.  
  6.  ;     Assemble in "PC-relative" mode and save with a TOS extension. 
  7.  
  8.  ; Execution Instructions:
  9.  
  10.  ;     Execute program CMD_TEST.TOS from the desktop.  After reading the
  11.  ; program's output on the screen, terminate execution by pressing the
  12.  ; Return key.
  13.  
  14.  ; Function:
  15.  
  16.  ;     This program is used to compare the relative speed of the command
  17.  ; line processing algorithms used in SPEED_1, SPEED_2 and SPEED_3.
  18.  
  19.  ; Description:
  20.  
  21.  ;     Three command line processing algorithms are executed 10,000 times.
  22.  ; The elapsed time and requisite memory for each algorithm is printed to
  23.  ; the screen.  So that this program need not be executed as a TTP program,
  24.  ; the command line is salted with a declared string.
  25.  
  26. release_excess_memory:
  27.  lea        program_end, a0     ; Put "end of program" address in A0.
  28.  movea.l    4(a7), a1           ; Put "basepage" address in A1.
  29.  movea.l    a1, a5              ; Copy to A5 for command line access.
  30.  trap       #6                  ; Calculate program size and release memory.
  31.  lea        stack, a7           ; Point A7 to this program's stack.
  32.  
  33. mainline:
  34.  lea        heading, a0
  35.  bsr        print_string
  36.  
  37. salt_command_line:
  38.  lea        salt, a0            ; Fetch pointer to ersatz command line input.
  39.  movem.l    (a0), d0-d3         ; Move it to registers.
  40.  movem.l    d0-d3, $80(a5)      ; Copy to actual command line address.
  41.  
  42. speed_1_algorithm:
  43.  lea        speed_1_msg, a0
  44.  bsr        print_string
  45.  move.l     #9999, d4           ; Initialize counter for 10000 executions.
  46.  trap       #3                  ; Get start time.
  47.  move.l     d0, d5              ; Copy for calculations.
  48. speed_1_loop:
  49.  lea        $80(a5), a4         ; Fetch address of parameters.
  50.  move.b     (a4)+, d0           ; Fetch parameter line character count.
  51.  lea        program_name_1, a3  ; Load buffer address.
  52.  subq.b     #1, d0              ; Set up counter.
  53.  ext.w      d0                  ; Extend to match the size of the dbra
  54.                                 ; instruction.
  55. fetch_character:                
  56.  move.b     (a4)+, (a3)+        ; Store character.
  57.  dbra       d0, fetch_character ; Loop until D0 becomes negative.
  58.  move.b     #0, (a3)            ; Finish with a NULL.
  59. create_file_name:               ; Create a file to accept standard output.
  60.  lea        filename_1, a4      ; Load buffer address.
  61.  lea        program_name_1, a3  ; Load buffer address.
  62. copy_name:
  63.  move.b     (a3)+, (a4)+
  64.  cmpi.b     #$2E, (a3)          ; Is next byte of program_name the period?
  65.  bne.s      copy_name           ; Continue looping until period is seen.
  66.  move.b     #$2E, (a4)+         ; Add a period.
  67.  move.b     #$44, (a4)+         ; Add letter 'D'.
  68.  move.b     #$41, (a4)+         ; Add letter 'A'.
  69.  move.b     #$54, (a4)+         ; Add letter 'T'.
  70.  move.b     #0, (a4)            ; Add a NULL.
  71. speed_1_memory:
  72.  dbra       d4, speed_1_loop    ; Loop until D4 becomes negative.
  73.  trap       #3                  ; Get end time.
  74.  bsr        convert_and_print_time
  75.  
  76. speed_2_algorithm:
  77.  lea        speed_2_msg, a0
  78.  bsr        print_string
  79.  move.l     #9999, d4           ; Initialize counter for 10000 executions.
  80.  trap       #3                  ; Get start time.
  81.  move.l     d0, d5              ; Copy for calculations.
  82. speed_2_loop:
  83.  lea        input_line, a3      ; Fetch location to contain command line.
  84.  lea        output_line_2, a4   ; A second location: for filename.
  85.  movem.l    $80(a5), d0-d3      ; Move 16 bytes of command line to 4 registers.
  86.  movem.l    d0-d3, (a3)         ; Move them to address "input_line".
  87.  movem.l    d0-d3, (a4)         ; Move them to address "output_line".
  88.  move.b     $80(a5), d0         ; Fetch command line ASCII character count.
  89.  ext.w      d0                  ; Extend to word for next instruction.
  90.  move.b     #0, 1(a3,d0.w)      ; Store a null at end of command line input.
  91.  move.b     #0, 1(a4,d0.w)      ; Same for filename buffer.
  92. insert_filename_suffix:
  93.  move.b     #$44, -2(a4,d0.w)   ; Insert letter 'D'.
  94.  move.b     #$41, -1(a4,d0.w)   ; Insert letter 'A'.
  95.  move.b     #$54,  0(a4,d0.w)   ; Insert letter 'T'.
  96. speed_2_memory:
  97.  dbra       d4, speed_2_loop    ; Loop until D4 becomes negative.
  98.  trap       #3                  ; Get end time.
  99.  bsr        convert_and_print_time
  100.  
  101. speed_3_algorithm:
  102.  lea        speed_3_msg, a0
  103.  bsr        print_string
  104.  move.l     #9999, d4           ; Initialize counter for 10000 executions.
  105.  lea        $80(a5), a5         ; Fetch command line address.
  106.  trap       #3                  ; Get start time.
  107.  move.l     d0, d5              ; Copy for calculations.
  108. speed_3_loop:
  109.  
  110.  ; NOTE: The first instruction, below, is not used in the actual SPEED_3
  111.  ;       algorithm, but it must be included here to reset A3 to the
  112.  ;       correct address each time through the loop.  This instruction
  113.  ;       adds 4 clock periods per loop, 40000 clock periods for the
  114.  ;       10000 loops, which is 5 milliseconds.  The accuracy of this error
  115.  ;       calculation was confirmed by executing CMD_TEST.TOS with and 
  116.  ;       without the instruction in the loop.  The 5 msec error is equal to
  117.  ;       one system clock tick, therefore, when the loop end-time is obtained
  118.  ;       with the trap #3 invocation, 1 clock tick is subtracted before the
  119.  ;       loop time is calculated.
  120.  
  121.  ;       The memory occupied by this instruction is not included in the
  122.  ;       value reported for the algorithm's requisite memory.
  123.  
  124.  movea.l    a5, a3
  125. start_memory:
  126.  lea        output_line_3, a4    ; Fetch location to contain command line.
  127.  movem.l    (a3), d0-d3          ; Move 16 bytes of command line to 4 registers.
  128.  movem.l    d0-d3, (a4)          ; Move them to address "command_line".
  129.  move.b     (a3)+, d0            ; Fetch command line ASCII character count.
  130.  ext.w      d0                   ; Extend to word for next instruction.
  131.  move.b     #0, 1(a4,d0.w)       ; Store a null at end of string.
  132.  lea        program_name_ptr, a0 ; Fetch address of pointer to program name.
  133.  move.l     a3, (a0)             ; Store address of filename string in pointer.
  134.  move.b     #0, 0(a3,d0.w)       ; Replace $0D at end of program name with NULL.
  135.                        
  136. _insert_filename_suffix:
  137.  move.b     #$44, -2(a4,d0.w)   ; Insert letter 'D'.
  138.  move.b     #$41, -1(a4,d0.w)   ; Insert letter 'A'.
  139.  move.b     #$54,  0(a4,d0.w)   ; Insert letter 'T'.
  140. speed_3_memory:
  141.  dbra       d4, speed_3_loop
  142.  trap       #3
  143.  subq.w     #1, d0               ; Subtract 1 clock tick to correct time.
  144.  bsr.s      convert_and_print_time
  145.  
  146. speed_1_requisite_memory:
  147.  lea        speed_1_memory_msg, a0
  148.  bsr.s      print_string
  149.  lea        speed_1_loop, a1    ; Calculate number of bytes occupied by the
  150.  lea        speed_1_memory, a0  ; instructions in the loop, then print.
  151.  bsr.s      calculate_and_print_requisite_memory
  152.  
  153. speed_2_requisite_memory:
  154.  lea        speed_2_memory_msg, a0
  155.  bsr.s      print_string
  156.  lea        speed_2_loop, a1     ; Calculate number of bytes occupied by the
  157.  lea        speed_2_memory, a0   ; instructions in the loop, then store.
  158.  bsr.s      calculate_and_print_requisite_memory
  159.  
  160. speed_3_requisite_memory:
  161.  lea        speed_3_memory_msg, a0
  162.  bsr        print_string
  163.  lea        start_memory, a1    ; Calculate number of bytes occupied by the
  164.  lea        speed_3_memory, a0  ; instructions in the loop, then print.
  165.  bsr.s      calculate_and_print_requisite_memory
  166.  
  167. wait_for_keypress: 
  168.  move.w     #8, -(sp)           ; Function = c_necin = GEMDOS $8.
  169.  trap       #1                  ; GEMDOS call.
  170.  addq.l     #2, sp              ; Reposition stack pointer at top of stack.
  171.  
  172. terminate:
  173.  move.w     #0, -(sp)
  174.  trap       #1
  175.  
  176. print_string:                   ; Expects address of string to be in A0.
  177.  pea        (a0)                ; Push address of string onto stack.
  178.  move.w     #9, -(sp)           ; Function = c_conws = GEMDOS $9.
  179.  trap       #1                  ; GEMDOS call
  180.  addq.l     #6, sp              ; Reset stack pointer to top of stack.
  181.  rts
  182.  
  183. convert_and_print_time:
  184.  sub.l      d5, d0              ; Subtract start time from end time.
  185.  mulu       #5, d0              ; Convert to milliseconds.
  186.  move.l     d0, d1              ; Convert to ASCII decimal.
  187.  trap       #4
  188.  bsr        print_string
  189.  lea        time_label, a0
  190.  bsr        print_string
  191.  rts
  192.  
  193. calculate_and_print_requisite_memory:
  194.  suba.l     a1, a0
  195.  move.l     a0, d1              ; Transfer requisite memory for trap call.
  196. print_speed_1_requisite_memory:
  197.  trap       #4                  ; Returns address of decimal string in A0.
  198.  bsr        print_string
  199.  lea        memory_label, a0
  200.  bsr        print_string
  201.  rts
  202.  
  203.  data
  204. salt:               dc.b $B,"PRG_5AP.TOS",$D,0,0,0,0
  205. heading:            dc.b $D,$A,"CMD_TEST Execution Results",$D,$A,$D,$A,0
  206. speed_1_msg:        dc.b       "  SPEED_1 algorithm time: ",0
  207. speed_2_msg:        dc.b       "  SPEED_2 algorithm time: ",0
  208. speed_3_msg:        dc.b       "  SPEED_3 algorithm time: ",0
  209. time_label:         dc.b " milliseconds",$D,$A,0
  210. speed_1_memory_msg: dc.b $D,$A,"  SPEED_1 algorithm requisite memory: ",0
  211. speed_2_memory_msg: dc.b       "  SPEED_2 algorithm requisite memory: ",0
  212. speed_3_memory_msg: dc.b       "  SPEED_3 algorithm requisite memory: ",0
  213. memory_label:       dc.b " bytes",$D,$A,0
  214.  align
  215.  bss
  216. program_name_1:   ds.l    4   ; Program name buffer for SPEED_1 algorithm.
  217. filename_1:       ds.l    4   ; Filename buffer for SPEED_1 algorithm.
  218. input_line:       ds.b    1   ; Command line buffer for SPEED_2 algorithm.
  219. program_name_2:   ds.b   15   ; Program name buffer for SPEED_2 algorithm.
  220. output_line_2:    ds.b    1   ; Second command line buffer for SPEED_2.
  221. filename_2:       ds.b   15   ; Filename buffer for SPEED_2 algorithm.
  222. program_name_ptr: ds.l    4   ; Pointer to filename in command line for SPEED_3.
  223. output_line_3:    ds.b    1   ; Command line buffer for SPEED_3 algorithm.
  224. filename_3:       ds.b   15   ; Filename buffer for SPEED_3 algorithm.
  225.                   ds.l   96   ; Program stack.
  226. stack:            ds.l    0   ; Address of program stack.
  227. program_end:      ds.l    0
  228.  end